package com.common.app.db

import androidx.room.*
import com.common.app.data.bean.CloudDownDataModel

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2025/08/05
 * <p>
 * 描述：云端下载数据Dao类
 * <p>
 * 修订历史：
 */
@Dao
interface CloudDownDataDao {

    // 插入
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg event: CloudDownDataModel)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(mList:List<CloudDownDataModel>)

    // 删除
    @Delete
    fun delete(list: MutableList<CloudDownDataModel>)

    // 删除
    @Delete
    fun deleteAll(list: List<CloudDownDataModel>)

    //删除所有 → '所有'的只能用@Query,@Query可以编写任意的sql语句
    @Query("DELETE FROM cloud_down_data")
    fun deleteAll()

    // 查询
    @Query("select * from cloud_down_data")
    fun findAll(): MutableList<CloudDownDataModel>

    @Query("select count(*) from cloud_down_data")
    fun count(): Int

    // 修改
    @Update
    fun update(event: CloudDownDataModel)

    @Query("select * from cloud_down_data WHERE userId =:id ORDER BY id DESC")
    fun findById(id: String): MutableList<CloudDownDataModel>

    // 查询 所有  倒序 查询
    @Query("SELECT * FROM cloud_down_data WHERE userId =:id ORDER BY id DESC  LIMIT :mSize")
    fun findByIdDescSize(id: String, mSize: Int): MutableList<CloudDownDataModel>
}